#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>

int maxArea(vector<int>& height) {
    int left = 0;
    int right = height.size() - 1;
    int ret = 0;
    while (left < right)
    {
        int v = min(height[left], height[right]) * (right - left);
        ret = max(v, ret);
        if (height[left] < height[right])
        {
            left++;
        }
        else
        {
            right--;
        }
    }
    return ret;
}

int sum(int n)
{
    int ret = 0;
    while (n)
    {
        int tmp = n % 10;
        ret += tmp * tmp;
        n /= 10;
    }
    return ret;
}
bool isHappy(int n) {
    int slow = n;
    int fast = sum(n);
    while (slow != fast)
    {
        slow = sum(slow);
        fast = sum(sum(fast));
    }
    return slow == 1;
}

int triangleNumber(vector<int>& nums) {
    sort(nums.begin(), nums.end());
    int max = nums.size() - 1;
    int count = 0;
    while (max >= 0)
    {
        int left = 0;
        int right = max - 1;
        while (left < right)
        {
            if (nums[left] + nums[right] > nums[max])
            {
                count += right - left;
                right--;
            }
            else
            {
                left++;
            }
        }
        max--;
    }
    return count;
}

int removeDuplicates(vector<int>& nums) {
    int n = nums.size();
    if (n < 3)
    {
        return n;
    }
    int slow = 2;
    int fast = 2;
    while (fast < n)
    {
        if (nums[slow - 2] != nums[fast])
        {
            nums[slow] = nums[fast];
            slow++;
        }
        fast++;
    }
    return slow;
}